home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 5 code / Lisp Mini-App / build-and-run-mini-app.lisp < prev    next >
Encoding:
Text File  |  1992-04-08  |  6.2 KB  |  181 lines  |  [TEXT/CCL2]

  1. #|
  2.    build-and-run-mini-app.lisp
  3.  
  4.    To compile and load and start the Mini-Application, load this file.
  5.  
  6.    For further info, see files "About Mini-App" and "Instructions".
  7.  
  8.  
  9.    Portions copyright ©1989-1992 Apple Computer, Inc
  10.  
  11.    Change History.
  12.    03-12-92 slm  Updated file header comments.
  13.    03-06-92 slm  Deliberately and shamelessly lifted most of the IFT's
  14.                     "ccl:Interface Tools:make-ift.lisp".
  15.                  This is a tutorial; we define no "package".
  16.  
  17.  
  18.     A simple defsystem.
  19.  
  20.     The defsystem defines the following:
  21.        - dependencies between files (what must compile or load before what).
  22.          In this case, dependencies are enforced by a 2-level strategy:
  23.          1. Procedurally by partitioning files into 4 groups (coarse).
  24.             The groups are loaded in a fixed order.
  25.          2. Lexically by ordering files within each group (fine).
  26.             The files within each group are loaded in forward order.
  27.        - "support" files - macros, patches and low-level code
  28.        - "module" files - These are libraries that at the end of
  29.             their source files call #'provide with their colloquial name.
  30.             See docs on #'provide and *modules*. 
  31.        - "core" files - Menus, palettes, behavior, etc
  32.        - "application" files - Palette item instances, specific behavior.
  33.  
  34.     To better understand this draw a call graph, starting with load-app.
  35.  
  36.     More sophisticated dependencies, such as what other files must be
  37.     recompiled if a certain file is recompiled, are not implemented.    
  38. |#
  39.  
  40. (unless (and
  41.          (equalp "Mini-Application"
  42.                  (car (last (butlast (pathname-directory
  43.                                       (translate-logical-pathname "ccl:mini-app;"))))))
  44.          (equalp "Program"
  45.                  (car (last (pathname-directory
  46.                              (translate-logical-pathname "ccl:mini-app;"))))))
  47.   (ccl::add-logical-pathname-translation
  48.    "ccl" '("mini-app;**;*.*" "ccl:Mini-Application;Program;*.*")))
  49.  
  50. (defparameter *app-support-files* 
  51.   '("ccl:mini-app;open-all-text-files"))
  52.  
  53. (defparameter *app-modules* '((quickdraw . "ccl:library;QuickDraw")))
  54.  
  55. (defparameter *app-core-files* 
  56.   '("ccl:mini-app;globals" 
  57.     "ccl:mini-app;utilities"
  58.     "ccl:mini-app;draw-dialog-class" 
  59.     "ccl:mini-app;menus" 
  60.     "ccl:mini-app;palette-class" 
  61.     "ccl:mini-app;draw-item-class" 
  62.     "ccl:mini-app;default-handlers" ; for DRAW-DIALOG windows & DRAW-ITEM objects
  63.     "ccl:mini-app;start-application"))
  64.  
  65. (defparameter *app-files* '("ccl:mini-app;mini-app-example"))
  66.  
  67. (defvar *loaded-app-files* '() "Keep track of files that are loaded.")  
  68.  
  69. (defun compile-if-changed (file always)
  70.   "Compiles file if not compiled, if changed, or if always is t."
  71.   (let* ((source (merge-pathnames file ".lisp"))
  72.          (fasl   (merge-pathnames file ".fasl")))
  73.     (unless (probe-file source)
  74.       (error "file not found: ~s" file))
  75.     (when (or always
  76.               (not (probe-file fasl))
  77.               (< (file-write-date fasl)
  78.                  (file-write-date source)))
  79.       (compile-file source :output-file fasl :verbose t))))
  80.  
  81. (defun load-if-changed (file always)
  82.   "Loads fasl file if not loaded or if changed, compiling first if necessary."
  83.   (compile-if-changed file nil)
  84.   (let* ((fasl (merge-pathnames file ".fasl"))
  85.          (date (file-write-date fasl))
  86.          (last-load (assoc file *loaded-app-files* :test #'equalp)))
  87.     (when (or always
  88.               (not last-load)
  89.               (< (cdr last-load)
  90.                  date))
  91.       (load fasl :verbose t)
  92.       (if last-load
  93.           (setf (cdr last-load) date)
  94.           (push (cons file date) *loaded-app-files*)))))
  95.  
  96. (defun load-app-support ()
  97.   "Loads support fasl files, compiling first if necessary."
  98.   (dolist (file *app-support-files*)
  99.     (load-if-changed file nil)))
  100.  
  101. (defun load-app-modules ()
  102.   "Loads library (module) fasl files, compiling first if necessary."
  103.   (dolist (module *app-modules*)
  104.     (destructuring-bind (module-name . file) module
  105.       (when (or (not (member module-name *modules* :test 'string-equal))
  106.                 (compile-if-changed file nil))
  107.         (load-if-changed file nil)))))
  108.  
  109. (defun load-app-core-files ()
  110.   "Loads core files, if not loaded or if changed."
  111.   (dolist (file *app-core-files*)
  112.     (load-if-changed file nil)))
  113.  
  114. (defun load-app-files ()
  115.   "Loads application files, if not loaded or if changed."
  116.   (dolist (file *app-files*)
  117.     (load-if-changed file nil)))
  118.  
  119. (defun load-app ()
  120.   "Loads support, module and application files, if not loaded or if changed."
  121.   (with-compilation-unit ()
  122.     (load-app-support))
  123.   (with-compilation-unit ()
  124.     (load-app-modules))  ;modules are compiled if changed or not yet compiled
  125.   (with-compilation-unit ()
  126.     (load-app-core-files))
  127.   (with-compilation-unit ()
  128.     (load-app-files))
  129.   (pushnew :mini-app *features*))
  130.  
  131.  
  132. ;;; __________________________________________________________________
  133. ;;; START MINI APPLICATION
  134.  
  135. ;;;   Start up our little application.
  136. ;;;
  137.  
  138. (progn
  139.   (load-app)
  140.   (start-application))    ;in ccl:mini-app;start-application
  141.  
  142.  
  143. ;;; Record this application as loaded (Common Lisp bookkeeping)
  144. ;;;
  145. (provide :mini-application)
  146.  
  147.  
  148. #|
  149.  
  150. If you really want to compile the Mini-Application without loading it
  151.    (warning: this wasn't tested, because I don't use it):
  152.  
  153. ;(compile-app)     ;compiles any files that need compiling
  154. ;(compile-app T)   ;compiles all files unconditionally
  155.  
  156. (defun compile-core-files (&optional always)
  157.   "Compiles core files, if changed or if always is t."
  158.   (dolist (file *app-core-files*)
  159.     (compile-if-changed file always)))
  160.  
  161. (defun compile-app-files (&optional always)
  162.   "Compiles application files, if changed or if always is t."
  163.   (dolist (file *app-files*)
  164.     (compile-if-changed file always)))
  165.  
  166. (defun compile-app (&optional always)
  167.   "Loads support and module files, and compiles application files,
  168.    if changed or if always is t."
  169.   (with-compilation-unit ()
  170.     (load-app-support))   ;it is necessary to load the support files
  171.   (with-compilation-unit ()
  172.     (load-app-modules))   ;it is necessary to load the library files
  173.   (with-compilation-unit ()
  174.     (compile-core-files always))
  175.   (with-compilation-unit ()
  176.     (compile-app-files always)))
  177. |#
  178.  
  179. ;end of file build-and-run-mini-app.lisp
  180. ;------------------------------------------------
  181.